<?php

if (!function_exists('array_keep')) {
    /**
     * 保存数组中指定的键值对
     * @param array $array
     * @param null $page
     * @param null $limit
     * @return array
     */
    function array_keep($array = [], $keys_to_keep=[]){
        // 使用 array_flip 将要保留的键转换为一个翻转后的数组
        $flipped_keys = array_flip($keys_to_keep);
        // 使用 array_intersect_key 保留指定的键值对
        $new_array = array_intersect_key($array, $flipped_keys);
        return $new_array;
    }
}

if (!function_exists('get_transport_scene_list_obj')) {
    /**
     * 获取货运种类的对象
     */
    function get_transport_scene_list_obj(){
        $transport_scene_list_arr = sysconf('transport_scene_list_arr');
        $transport_scene_list_arr = html_entity_decode($transport_scene_list_arr, ENT_QUOTES, 'UTF-8');
        $transport_scene_list_arr = json_decode($transport_scene_list_arr, true);
        $transport_scene_list_arr = array_column($transport_scene_list_arr, null, 'name');
        return $transport_scene_list_arr;
    }
}

if (!function_exists('get_transport_distance_list_arr')) {
    /**
     * 获取货运种类的数组
     */
    function get_transport_distance_list_arr(){
        $transport_distance_list_arr = sysconf('transport_distance_list_arr');
        $transport_distance_list_arr = html_entity_decode($transport_distance_list_arr, ENT_QUOTES, 'UTF-8');
        $transport_distance_list_arr = json_decode($transport_distance_list_arr, true);
        return $transport_distance_list_arr;
    }
}

if (!function_exists('get_transport_distance_list_obj')) {
    /**
     * 获取货运种类的对象
     */
    function get_transport_distance_list_obj(){
        $transport_distance_list_arr = sysconf('transport_distance_list_arr');
        $transport_distance_list_arr = html_entity_decode($transport_distance_list_arr, ENT_QUOTES, 'UTF-8');
        $transport_distance_list_arr = json_decode($transport_distance_list_arr, true);
        $transport_distance_list_arr = array_column($transport_distance_list_arr, null, 'name');
        return $transport_distance_list_arr;
    }
}

if (!function_exists('get_task_pilot_money')) {
    /**
     * 获取飞手端价格
     */
    function get_task_pilot_money($money){
        $transport_commission = intval(sysconf('transport_commission'));
        return bcmul($money, (100 - $transport_commission) * 0.01,  2);
    }
}
